<template>
  <div>
    <el-dialog
      :visible.sync="dialog.add"
      :close-on-click-modal="false"
      title="添加"
      width="80%"
      append-to-body
      @closed="dialogClosed('addForm')"
    >
      <el-form ref="addForm" :model="form" label-width="120px" :rules="validateRules">
        <el-row>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="用户手机号" prop="userPhone">
              <el-input v-model="form.userPhone" placeholder="请输入用户手机号" disabled clearable />
              <el-button
                type="text"
                size="small"
                @click="showJoinSearch({
                searchDialog: 'UserMain'
              })"
              >选择用户手机号</el-button>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="用户昵称" prop="userNickname">
              <el-input v-model="form.userNickname" placeholder="请输入用户昵称" disabled clearable />
              <el-button
                type="text"
                size="small"
                @click="showJoinSearch({
                searchDialog: 'UserMain'
              })"
              >选择用户昵称</el-button>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="内部单号" prop="orderNo">
              <el-input v-model="form.orderNo" placeholder="请输入内部单号" clearable />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="金额（元）" prop="amount">
              <el-input-number
                v-model="form.amount"
                placeholder="请输入金额（元）"
                clearable
                style="width: 100%;"
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="冻结或解冻" prop="frezeeType">
              <el-select
                v-model="form.frezeeType"
                placeholder="请选择冻结或解冻"
                clearable
                style="width: 100%;"
              >
                <el-option
                  v-for="item in selects.frezeeTypeSelect"
                  :value="item.value"
                  :key="item.value"
                  :label="item.displayValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
            <el-form-item label="冻结描述" prop="frezeeDescription">
              <el-input
                type="textarea"
                v-model="form.frezeeDescription"
                placeholder="请输入冻结描述"
                clearable
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer">
        <el-button @click="dialog.add = false">取消</el-button>
        <el-button type="primary" @click="add" :loading="loading.add">添加</el-button>
      </div>
    </el-dialog>
    <el-dialog
      :visible.sync="dialog.edit"
      :close-on-click-modal="false"
      title="修改"
      width="80%"
      append-to-body
      @closed="dialogClosed('editForm')"
    >
      <el-form ref="editForm" :model="form" label-width="120px" :rules="validateRules">
        <el-row>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="用户手机号" prop="userPhone">
              <el-input v-model="form.userPhone" placeholder="请输入用户手机号" disabled clearable />
              <el-button
                type="text"
                size="small"
                @click="showJoinSearch({
                searchDialog: 'UserMain'
              })"
              >选择用户手机号</el-button>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="用户昵称" prop="userNickname">
              <el-input v-model="form.userNickname" placeholder="请输入用户昵称" disabled clearable />
              <el-button
                type="text"
                size="small"
                @click="showJoinSearch({
                searchDialog: 'UserMain'
              })"
              >选择用户昵称</el-button>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="内部单号" prop="orderNo">
              <el-input v-model="form.orderNo" placeholder="请输入内部单号" clearable />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="金额（元）" prop="amount">
              <el-input-number
                v-model="form.amount"
                placeholder="请输入金额（元）"
                clearable
                style="width: 100%;"
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="冻结或解冻" prop="frezeeType">
              <el-select
                v-model="form.frezeeType"
                placeholder="请选择冻结或解冻"
                clearable
                style="width: 100%;"
              >
                <el-option
                  v-for="item in selects.frezeeTypeSelect"
                  :value="item.value"
                  :key="item.value"
                  :label="item.displayValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
            <el-form-item label="冻结描述" prop="frezeeDescription">
              <el-input
                type="textarea"
                v-model="form.frezeeDescription"
                placeholder="请输入冻结描述"
                clearable
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer">
        <el-button @click="dialog.edit = false">取消</el-button>
        <el-button type="primary" @click="edit" :loading="loading.edit">修改</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import * as utils from '@/utils/utils'
import * as ResponseStatus from '@/utils/response-status'
import UploadImage from '@/components/Upload/UploadImage'
import Tinymce from '@/components/Tinymce'
const resUrl = process.env.VUE_APP_RES_URL
export default {
  name: 'FundsFrezeeAddEdit',
  components: {
    UploadImage,
    Tinymce,
  },
  data() {
    return {
      dialog: {
        add: false,
        edit: false,
      },
      loading: {
        add: false,
        edit: false,
      },
      form: {
        userId: undefined,
        userPhone: undefined,
        userNickname: undefined,
        userIsActive: undefined,
        orderNo: undefined,
        amount: undefined,
        frezeeType: undefined,
        frezeeDescription: undefined,
      },
      validateRules: {
        userId: [
          {
            type: 'integer',
            required: true,
            message: '此项为必须项',
            trigger: 'blur, change',
          },
        ],
        userPhone: [
          {
            type: 'string',
            required: true,
            message: '此项为必须项',
            trigger: 'blur',
          },
          {
            type: 'string',
            min: 1,
            max: 11,
            message: '必须1-11个字符',
            trigger: 'blur',
          },
        ],
        userNickname: [
          {
            type: 'string',
            required: true,
            message: '此项为必须项',
            trigger: 'blur',
          },
          {
            type: 'string',
            min: 1,
            max: 50,
            message: '必须1-50个字符',
            trigger: 'blur',
          },
        ],
        userIsActive: [
          {
            type: 'integer',
            required: true,
            message: '此项为必须项',
            trigger: 'blur, change',
          },
        ],
        orderNo: [
          {
            type: 'string',
            required: true,
            message: '此项为必须项',
            trigger: 'blur',
          },
          {
            type: 'string',
            min: 1,
            max: 50,
            message: '必须1-50个字符',
            trigger: 'blur',
          },
        ],
        amount: [
          {
            type: 'number',
            required: true,
            message: '此项为必须项',
            trigger: 'blur, change',
          },
        ],
        frezeeType: [
          {
            type: 'integer',
            required: true,
            message: '此项为必须项',
            trigger: 'blur, change',
          },
        ],
        frezeeDescription: [
          {
            type: 'string',
            min: 1,
            max: 255,
            message: '必须1-255个字符',
            trigger: 'blur',
          },
        ],
      },
      dataDictCodes: ['YES_NO', 'FREZEE_TYPE'],
      selects: {
        userIsActiveSelect: [],
        frezeeTypeSelect: [],
      },
      resUrl: resUrl,
    }
  },
  computed: {},
  mounted() {
    this.initDataDict()
  },
  methods: {
    initDataDict() {
      utils
        .getDataDict(this.dataDictCodes)
        .then((response) => {
          if (response) {
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'YES_NO',
              formProp: 'userIsActive',
              dataProp: 'userIsActiveSelect',
            })
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'FREZEE_TYPE',
              formProp: 'frezeeType',
              dataProp: 'frezeeTypeSelect',
            })
          }
        })
        .catch((error) => {})
    },
    dialogClosed(formRef) {
      this.$refs[formRef].resetFields()
      for (let key in this.form) {
        this.form[key] = undefined
      }
    },
    add() {
      this.$emit('add')
    },
    edit() {
      this.$emit('edit')
    },
    /** 触发父组件展示关联表数据的搜索对话框 */
    showJoinSearch(options) {
      this.$emit('showJoinSearchDialog', options)
    },
    imgUploadSuccess(formProp, url) {
      this.form[formProp] = url
    },
    imgRemoveSuccess(formProp) {
      this.form[formProp] = undefined
    },
  },
}
</script>

<style>
</style>